<!--
 * @Author: 高瑞寒 15932717091@163.com
 * @Date: 2022-04-25 09:18:08
 * @LastEditTime: 2022-04-25 09:42:08
 * @LastEditors: 高瑞寒 15932717091@163.com
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="test"></div>
  <script type="text/javascript" src="../js/react.development.js"></script>
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../js/babel.min.js">
  </script>
  <script src="../js/prop-types.js"></script>
  <script type="text/babel">

    class MyComponent extends React.Component {
      state = { count: 0 }
      bindInput = (e) => {
        this.refInput = e
        console.log(e);
        this.setState({ count: ++this.state.count })
      }
      handleBlur = () => {
        console.log(this.refInput);
      }
      handleClick = () => {
        this.refInput.value = this.refInput2.value
        // 改变 state 触发 render
        this.setState({ count: ++this.state.count })
      }
      render() {
        // 内联绑定 ref 会触发两次,但不造成影响
        return (
          <div>
            <div>{this.state.count}</div>
            <input type="text" ref={this.bindInput} onBlur={this.handleBlur} /><br />
            <input type="text" ref={(e) => { this.refInput2 = e; console.log(e); }} />
            <button onClick={this.handleClick}>点击</button>
          </div>
        )
      }
    }
    ReactDOM.render(<div><MyComponent /></div>, document.querySelector('#test'))
  </script>
</body>

</html>